package io.bsly.modules.sys.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.bsly.common.utils.Constant;
import io.bsly.common.utils.JsonUtils;
import io.bsly.common.utils.R;
import io.bsly.modules.app.entity.localEntity.DyOrderEntity;
import io.bsly.modules.app.entity.localEntity.UserEntity;
import io.bsly.modules.app.service.localmaster.DyOrderService;
import io.bsly.modules.app.service.localmaster.UserService;
import io.bsly.modules.sys.pojo.StatisticsVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "后台统计")
@RestController
@RequestMapping("/sys/statistics")
public class SysStatisticsController {

    //抖音用户
    @Autowired
    UserService userService;

    @Autowired
    private DyOrderService dyOrderService;

    @ApiOperation("获取统计数据")
    @PostMapping("/data")
    public R statistics(){
        int userCount = userService.count(Wrappers.lambdaQuery(UserEntity.class).eq(UserEntity::getStatus, 1));
        int orderNew = dyOrderService.count(Wrappers.<DyOrderEntity>lambdaQuery().eq(DyOrderEntity::getStatus, Constant.OrderStatus.WAIT.getValue()));
        int orderDone = dyOrderService.count(Wrappers.<DyOrderEntity>lambdaQuery().eq(DyOrderEntity::getStatus, Constant.OrderStatus.DONE.getValue()));
        int orderRunning = dyOrderService.count(Wrappers.<DyOrderEntity>lambdaQuery().eq(DyOrderEntity::getStatus, Constant.OrderStatus.CONFIRMED.getValue()));

        StatisticsVo statisticsVo = new StatisticsVo();
        statisticsVo.setOrderNew(orderNew);
        statisticsVo.setOrderOver(orderDone);
        statisticsVo.setOrderRuning(orderRunning);
        statisticsVo.setUserCount(userCount);
        return R.ok().put("data", JsonUtils.toJson(statisticsVo));
    }



}
